
---@class CustomFollowHandler:ActionHandlerBase
CustomFollowHandler = class(ActionHandlerBase)

function CustomFollowHandler:Enter()
    self.base.Enter(self);
    Debug.Log("进入跟随动作")
    ---@type UnityEngine.Transform
    self._self = self:GetGameData(ECustomDataName.SelfTrans);
    ---@type UnityEngine.CharacterController
    self._controller = self._self:GetComponent(typeof(CS.UnityEngine.CharacterController));
end

function CustomFollowHandler:Execute()
    self.base.Execute(self);
    ---@type UnityEngine.Transform
    local targetTrans = self:GetGameData(ECustomDataName.TargetTrans)
    if CS.UnityEngine.Vector3.Distance(self._self.position, targetTrans.position) > 1.5 then
        local dirToEnemy = (targetTrans.position - self._self.position).normalized;
        self._controller:SimpleMove(dirToEnemy * 4);
    else
        self:OnComplete();
    end
end
